package com.ice.demo.java8;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class SwingTest {

    public static void main(String[] args) {

        // 创建窗体
        JFrame frame = new JFrame("Swing Test");
        // 创建按钮
        JButton button = new JButton("Click Me");
//        button.addActionListener(new ActionListener() {
//            @Override
//            public void actionPerformed(ActionEvent e) {
//                System.out.println("Button clicked!");
//            }
//        });
        button.addActionListener(e -> System.out.println("Button clicked!"));

        frame.add(button);
        frame.pack(); // 调用pack()方法，让窗体自适应组件大小
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }
}
